<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
</head>
<body>
<h2>标准登录页面</h2>
<h3>表单登录</h3>
<form id="formData" action="/user/login" method="POST">
    <table>
        <tr>
            <td>用户名:</td>
            <td><input type="text" name="username"/></td>
        </tr>
        <tr>
            <td>密码:</td>
            <td><input type="password" name="password"/></td>
        </tr>
        <tr>
            <td>验证码:</td>
            <td><input type="text" name="uuid" value="123456"></td>
        </tr>
        <tr>
            <td colspan='2'><input name="remember-me" type="checkbox"
                                   value="true"/>记住我
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <button type="button" id="commit">登录</button>
            </td>
        </tr>
    </table>
</form>
<script src="/js/cookies.js" type="text/javascript"></script>
<script src="/js/jquery.js" type="text/javascript"></script>
<script src="/js/layer/layer.js" type="text/javascript"></script>
<script type="text/javascript">
    $("#commit").click(function () {
        $.ajax({
            url: "/user/login",
            type: "POST",
            dataType: "JSON",
            headers: {
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: '{"username": "' + $("input[name='username']").val() + '","password": "' + $("input[name='password']").val() + '",' +
                '"uuid": "' + $("input[name='uuid']").val() + '"}',
            success: function (res) {
                if (res.status === 200) {
                    setCookie("token", res.data)
                    layer.msg('登录成功')
                    window.location.href='/index.html'
                } else {
                    alert(res.msg)
                }
            }
        })
    })
</script>
</body>
</html>